//
//  JCClubModel.m
//  SquashSpark
//
//  Created by 郭吉成 on 2017/11/23.
//  Copyright © 2017年 Coollang-YF. All rights reserved.
//

#import "JCClubModel.h"
#import "NSString+Extension.h"
#import "JCClubMessageModel.h"
#import "JCClubMemberModel.h"

@implementation JCClubModel

+ (NSDictionary *)creatFindClubList:(NSDictionary *)sourceDic{
    NSArray *recommendArray = [sourceDic[@"RecommendClub"] isEqual:[NSNull null]]?@[]:sourceDic[@"RecommendClub"];
    NSArray *clubArray = [sourceDic[@"ClubList"] isEqual:[NSNull null]]?@[]:sourceDic[@"ClubList"];
    NSMutableArray <JCClubModel *>*recommendList = [NSMutableArray array];
    NSMutableArray <JCClubModel *>*clubList = [NSMutableArray array];
    
    for (NSDictionary *dic in recommendArray) {
        JCClubModel *model = [JCClubModel creatModelWithData:dic];
        [recommendList addObject:model];
    }
    
    for (NSDictionary *dic in clubArray) {
        JCClubModel *model = [JCClubModel creatModelWithData:dic];
        [clubList addObject:model];
    }
    
    return @{@"recommed":[recommendList mutableCopy],
             @"list":[clubList mutableCopy]
             };
}

+ (JCClubModel *)creatModelWithData:(NSDictionary *)dataDic{
    JCClubModel *model = [JCClubModel new];
    model.clubID = [NSString checkIfNullWithString:dataDic[@"ID"]];
    model.ownerID = [NSString checkIfNullWithString:dataDic[@"OwnerID"]];
    model.name = [NSString checkIfNullWithString:dataDic[@"Name"]];
    model.describe = [NSString checkIfNullWithString:dataDic[@"Describe"]];
    model.banner = [NSURL URLWithString:[NSString checkIfNullWithString:dataDic[@"Banner"]]];
    model.headIcon = [NSURL URLWithString:[NSString checkIfNullWithString:dataDic[@"HeadIcon"]]];
    model.address = [NSString checkIfNullWithString:dataDic[@"Address"]];
    model.clubPhone = [NSString checkIfNullWithString:dataDic[@"ClubPhone"]];
    model.personalPhone = [NSString checkIfNullWithString:dataDic[@"PersonalPhone"]];
    model.recommed = [NSString checkIfNullWithString:dataDic[@"Recommend"]];
    model.creatTime = [NSString checkIfNullWithString:dataDic[@"CreateTime"]];
    model.updateTime = [NSString checkIfNullWithString:dataDic[@"UpdateTime"]];
    model.duration = [NSString checkIfNullWithString:dataDic[@"Duration"]];
    model.memberCount = [NSString checkIfNullWithString:dataDic[@"ClubMemberCount"]];
    model.rankNumber = [NSString checkIfNullWithString:dataDic[@"RankNo"]];
    
    //留言
    model.messageList = [JCClubMessageModel creatFindClubList:dataDic[@"MsgList"]];
    //运动情况
    model.lastWeekActiveTarget = [JCClubInfoSportItem creatModelWithData:dataDic[@"LastWeekActiveTarget"]];
    model.curWeekActiveTarget = [JCClubInfoSportItem creatModelWithData:dataDic[@"CurWeekActiveTarget"]];
    model.clubWeekTarget = [JCClubInfoSportItem creatModelWithData:dataDic[@"WeekTarget"]];
    
    model.curWeekFinishedCount = [NSString checkIfNullWithString:dataDic[@"CurWeekFinishedCount"]];   //本周完成的人员个数
    model.curWeekTotalActive = [NSString checkIfNullWithString:dataDic[@"CurWeekTotalActive"]]; //总参与个数
    model.lastWeekFinishedCount = [NSString checkIfNullWithString:dataDic[@"LastWeekFinishedCount"]];//上周完成的人员个数
    model.lastWeekTotalActive = [NSString checkIfNullWithString:dataDic[@"LastWeekTotalActive"]];//上周参与个数
    //人员排行列表
    model.rankList = [NSMutableArray array];
    NSArray *rankArray = dataDic[@"RankingList"];
    if (rankArray && ![rankArray isEqual:[NSNull null]]) {
        [model.rankList addObjectsFromArray:[JCClubMemberModel creatRankClubList:rankArray]];
    }
    return model;
}

@end





@implementation JCClubInfoSportItem

+ (JCClubInfoSportItem *)creatModelWithData:(NSDictionary *)dataDic{
    JCClubInfoSportItem *model = [JCClubInfoSportItem new];
    model.duration = [NSString checkIfNullWithString:dataDic[@"Duration"]];
    model.swings = [NSString checkIfNullWithString:dataDic[@"Swings"]];
    model.activeDays = [NSString checkIfNullWithString:dataDic[@"ActiveDays"]];
    return model;
}

@end
